# Maintainer: Tim Meusel <tim@bastelfreak.de>

_gemname='jwt'
pkgname="ruby-${_gemname}"
pkgver=2.7.1
pkgrel=1
pkgdesc='A pure ruby implementation of the RFC 7519 OAuth JSON Web Token (JWT) standard'
arch=('any')
url="https://github.com/jwt/${pkgname}"
license=('MIT')
depends=('ruby')
makedepends=('ruby-rdoc' 'ruby-rake' 'ruby-rspec' 'ruby-bundler')
checkdepends=('ruby-rubocop' 'ruby-simplecov')
options=('!emptydirs')
source=("${url}/archive/v${pkgver}/${_gemname}-v${pkgver}.tar.gz" 'drop-ci-dependencies.patch')
sha512sums=('efcdd81bc472a18764e0033f1040e9e2506952cbfb691acfc1ad90a5b34ebac864911e0cfeb28b82ac2ce1da7e3578a6677c0b113d1e45a81a3f4c4f8fed1047'
            '44895498a327428011d850d9e5a3aa6a36d85b3a505217f0586d58786d7b9408db5cce8a9c91ea50e08b278de4db85adb0edb2205f0bd70f02d664756d86a30d')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  rm Gemfile
  patch -p1 -N -i "${srcdir}/drop-ci-dependencies.patch"
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  gem build "${pkgname}.gemspec"
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  rake test --trace
}

package() {
cd "${srcdir}/${pkgname}-${pkgver}"
  local _gemdir="$(gem env gemdir)"
  gem install --verbose --ignore-dependencies --no-user-install --install-dir "${pkgdir}/${_gemdir}" --bindir "${pkgdir}/usr/bin" "${_gemname}-${pkgver}.gem"

  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}/"

  install -Dm 644 README.md AUTHORS CHANGELOG.md -t "${pkgdir}/usr/share/doc/${pkgname}"

  rm -rf "${pkgdir}/${_gemdir}/cache"
}
